local UIBase = require("view.UIBase")
local WaitMask = class("WaitMask", UIBase)
local Vector3 = require("utils.Vector3")

function WaitMask:ctor()
    local resource = {
        path = "Prefabs/UI",
        name = "WaitMask",
        canvas = 3
    }
    WaitMask.super.ctor(self, resource)
end

function WaitMask:showMask(show)
    self._show = show
    if show then
        if self._sequen then
            return
        end
        self.gameObject:SetActive(true)
        self._transformHourglass.gameObject:SetActive(false)
        local sequen = DOTween.Sequence()
        sequen:AppendInterval(0.3)
        sequen:AppendCallback(
            function()
                self._transformHourglass.gameObject:SetActive(true)
            end
        )

        local rotate = self._transformHourglass:DOLocalRotate(Vector3.new(0, 0, 180), 0.5)
        self._sequen = DOTween.Sequence()
        self._sequen:Append(rotate)
        local rotate2 = self._transformHourglass:DOLocalRotate(Vector3.new(0, 0, -180), 0.5)
        self._sequen:Append(rotate2)
        self._sequen:SetLoops(-1)
    else
        self.gameObject:SetActive(false)
        if self._sequen then
            self._sequen:Kill()
            self._sequen = nil
        end
    end
end

return WaitMask
